package com.ark.controller.game;

import com.ark.common.domain.entity.game.GameDevice;
import com.ark.common.response.Result;
import com.ark.common.utils.UUIDUtils;
import com.ark.service.service.GameDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/api/device")
public class GameDeviceController {

    @Resource
    private GameDeviceService gameDeviceService;

    @GetMapping("/list")
    public Result getDeviceList(GameDevice gameDevice) {

        return Result.success(gameDeviceService.getDeviceList(gameDevice));
    }

    @PostMapping
    public Result addDevice(@RequestBody GameDevice gameDevice) {
        GameDevice device = new GameDevice();
        device.setDeviceId(UUIDUtils.getShortUUID(true));
        device.setDeviceName(gameDevice.getDeviceName());
        device.setDeviceConfig(gameDevice.getDeviceConfig());
        boolean result = gameDeviceService.insertDevice(device);
        return result?Result.success():Result.error();
    }

    @PutMapping
    public Result updateDevice(@RequestBody GameDevice gameDevice) {
        boolean result = gameDeviceService.updateDevice(gameDevice);
        return result?Result.success():Result.error();
    }

    @DeleteMapping("/{deviceIds}")
    public Result deleteDevice(@PathVariable Long[] deviceIds) {
        return gameDeviceService.deleteDeviceByIds(deviceIds)?Result.success():Result.error();
    }
}
